package com.evildog.workspace.invest.application.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.evildog.workspace.dependencies.mybatis.object.QueryConditionDTO;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import org.springframework.util.Assert;
import com.evildog.workspace.common.object.PageQuery;
import com.evildog.workspace.common.result.PagedResult;
import com.evildog.workspace.invest.application.dto.BillTypePageDTO;
import com.evildog.workspace.invest.application.dto.BillTypeListDTO;
import com.evildog.workspace.invest.application.dto.BillTypeDTO;
import com.evildog.workspace.invest.application.bo.BillTypeBO;
import com.evildog.workspace.invest.application.bo.BillTypePageBO;
import com.evildog.workspace.invest.application.bo.BillTypeListBO;
import com.evildog.workspace.invest.application.convert.BillTypeConvert;
import java.util.List;
import com.evildog.workspace.invest.application.entity.BillType;
import com.evildog.workspace.invest.application.entity.BillTypePageDO;
import com.evildog.workspace.invest.application.entity.BillTypeListDO;
import com.evildog.workspace.invest.application.mapper.BillTypeMapper;
import com.evildog.workspace.invest.application.service.BillTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class BillTypeServiceImpl extends ServiceImpl<BillTypeMapper, BillType> implements BillTypeService {

    @Override
    public PagedResult<BillTypePageBO> getPageList(PageQuery query, List<QueryConditionDTO> queryConditions, BillTypePageDTO pageDTO) {
        IPage<BillTypePageDO> page = this.baseMapper.getPageList(
                QueryConditionUtils.getPagination(query),
                queryConditions,
                pageDTO);
        return BillTypeConvert.INSTANCE.convert(page);
    }

    @Override
    public List<BillTypeListBO> getList(List<QueryConditionDTO> queryCondition, BillTypeListDTO dto) {
        List<BillTypeListDO> billTypeList = this.baseMapper.getList(queryCondition, dto);
        return BillTypeConvert.INSTANCE.convert(billTypeList);
    }

    @Override
    public BillTypeBO getDetailById(Long id) {
        BillType billType = getById(id);
        Assert.notNull(billType, "billType is null!");
        return BillTypeConvert.INSTANCE.convert(billType);
    }

    @Override
    public boolean save(BillTypeDTO dto){
        BillType newBillType = BillTypeConvert.INSTANCE.convert(dto);
        return save(newBillType);
    }

    @Override
    public boolean updateById(Long id, BillTypeDTO dto){
        BillType oldBillType = getById(id);
        Assert.notNull(oldBillType, "billType is null!");
        BillType newBillType = BillTypeConvert.INSTANCE.convert(dto);
        newBillType.setId(id);
        return updateById(newBillType);
    }
}
